package com.dk.address;

import com.alibaba.dubbo.config.annotation.Service;
import com.dk.mapper.address.TbAddressMapper;
import com.dk.mapper.address.TbAreasMapper;
import com.dk.mapper.address.TbCitiesMapper;
import com.dk.mapper.address.TbProvincesMapper;
import com.dk.pojo.address.*;
import com.dk.service.address.AddressService;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

@Service
@Component
public class AddressServiceImpl implements AddressService {

    @Resource
    private TbAddressMapper addressMapper;

    @Resource
    private TbCitiesMapper citiesMapper;

    @Resource
    private TbAreasMapper areasMapper;

    @Resource
    private TbProvincesMapper provincesMapper;


    @Override
    public List<TbAddress> getAddressList(Long id) {
        String string = id.toString();
        TbAddressExample example = new TbAddressExample();
        TbAddressExample.Criteria criteria = example.createCriteria();
        criteria.andUserIdEqualTo(string);
        return addressMapper.selectByExample(example);
    }

    @Override
    public List<TbProvinces> getProvince() {
        return provincesMapper.selectByExample(null);
    }

    @Override
    public List<TbCities> getCities(String pid) {
        TbCitiesExample example = new TbCitiesExample();
        TbCitiesExample.Criteria criteria = example.createCriteria();
        criteria.andProvinceidEqualTo(pid);
        return citiesMapper.selectByExample(example);
    }

    @Override
    public List<TbAreas> getAreas(String cid) {
        TbAreasExample tbAreasExample = new TbAreasExample();
        TbAreasExample.Criteria criteria = tbAreasExample.createCriteria();
        criteria.andCityidEqualTo(cid);
        return areasMapper.selectByExample(tbAreasExample);
    }

    @Override
    public int saveAddress(TbAddress address) {
        return addressMapper.insertSelective(address);
    }
}
